import { post } from '../../utils/fetch'
import * as commonService from '../common'
import { rateAnalyzeDetail, dubangAnalyze } from '../../utils/api'
import * as Libs from '../../utils/Libs'
import * as _ from 'lodash'

export const getBuBang = async (params) => {
  return post(dubangAnalyze(params), {})
}

export const getDetailMsg = async (params) => {
  return post(rateAnalyzeDetail(params), {})
}

export const buildD = (tit, total, xq) => {
  const _title = { //营业利润title
    name: tit
  }
  let _content = []
  _.map(xq, (v) => {
    _content.push(geneContent(v))
  })
  return {
    title: _title,
    content: _content
  }
}

const geneContent = (v) => {
  const linked = {
    linkedName:'RateAnalyzeCommonStack'
  }
  let params = Object.assign({}, v, linked)
  // const _linked = v.isDetails === 1 ? params : undefined
  const _linked = params
  return {
    name: v.codeName,
    amount: Libs.numberUpperFormat(v.sumMoney || 0, false),
    linked: _linked,
    yoy: (v.onRise || '-'),
    qoq: (v.linkRise || '-'),
  }
}
